{% extends "site_base.html" %}

{% load i18n %}
{% load qa_tags %}
{% load qatrack_tags %}
{% load attach_tags %}
{% load comments %}
{% load static %}
{% load widget_tweaks %}

{% block head_title %}{% spaceless %}
    {% if test_list_instance %}
        Edit {{test_list_instance.unit_test_collection.unit.name}} : {{test_list_instance.test_list.name}}
    {% else %}
        Perform {{unit_test_collection.unit.name}} : {{test_list.name}}
    {% endif %}
{%endspaceless%}{% endblock %}

{% block extra_css %}

  <link href="{% static "qatrack_core/css/tables.css" %}?v={{VERSION}}" rel="stylesheet">
  <link href="{% static "qa/css/qa.css" %}?v={{VERSION}}" rel="stylesheet">
  <link href="{% static "faults/css/faults.css" %}?v={{VERSION}}" rel="stylesheet">
  <link href="{% static "icheck/css/blue.css" %}?v={{VERSION}}" rel="stylesheet">
  <link href="{% static "qatrack_core/css/sidebar.css" %}?v={{VERSION}}" rel="stylesheet">
  <link href="{% static "select2/css/select2.min.css" %}?v={{ VERSION }}" rel="stylesheet">
  <link href="{% static "qatrack_core/css/custom-select2.css" %}?v={{ VERSION }}" rel="stylesheet">
  <link href="{% static "flatpickr/css/flatpickr.css" %}?v={{ VERSION }}" rel="stylesheet">
  <link href="{% static "qatrack_core/css/flatpickr-custom.css" %}?v={{ VERSION }}" rel="stylesheet">
  <link href="{% static "cheekycheck/css/cheekycheck.css" %}?v={{ VERSION }}" rel="stylesheet">

{% endblock extra_css %}

{% block extra_js %}
    <script type="text/javascript">
        var unit_test_infos = {{unit_test_infos|safe}};
        var editing_tli = {{ test_list_instance.pk|default:"0"}};
        var has_errors = {% if has_errors %}true{% else %}false{% endif %};
        var override_date = false;
        {% if perms.qa.can_override_date %}
            override_date = true;
        {% endif %}
{#        var status_colours_dict = {{ status_tag_colours|safe }};#}
{#        var se_statuses = {{ se_statuses|safe }};#}
        var unit_id = {{ unit_test_collection.unit.id }};
        {% if test_list_instance.work_completed %}
            var work_completed_initial = "{{ test_list_instance.work_completed|safe }}";
        {% else %}
            var work_completed_initial = null;
        {% endif %}
        {% if test_list_instance.work_started %}
            var work_started_initial = "{{ test_list_instance.work_started|safe }}";
        {% else %}
            var work_started_initial = null;
        {% endif %}
    </script>

    <script id="attach-template" type="text/template">
        <div class="col-sm-6">
            <div class="row">
                <div class="col-sm-6">
                    <a target="_blank" href="<%= a.url %>">
                        <img class="img-responsive" src="<%= a.url %>" alt="<%= a.name %>"/>
                    </a>
                </div>
                <div class="col-sm-6">
                    <dl>
                        <dt>File</dt>
                        <dd>
                            <a target="_blank" href="<%= a.url %>"><%= a.name %></a>
                        </dd>

                        <dt>Size</dt>
                        <dd><%= a.size %></dd>
                    </dl>
                </div>
            </div>
        </div>
    </script>
{% endblock %}

{% block require_javascript %}
    require(['qa', 'faults'], function() {
        {{ test_list.javascript.strip|safe }}
    });
{% endblock require_javascript %}

{% block body_class %}sidebar-mini sidebar-collapse loading{% endblock body_class %}

{% block sidebar_toggle %}
    <a id="sidebar-toggle" href="#" class="sidebar-toggle pull-left" data-toggle="offcanvas" role="button">
        <i id="toggle-icon" class="fa fa-chevron-right fa-lg rotates" aria-hidden="true"></i>
    </a>
{% endblock sidebar_toggle %}

{% block body %}

    <div {% if not perms.qa.can_view_history %}class="max-width-md"{% endif %}>

    <form class="nosubmit form-inline" id="qa-form" method="POST" action="" autocomplete="off" enctype="multipart/form-data" >
        {% csrf_token %}

        <div id="box-contacts" class="row" style="display: none;">
            <div class="col-lg-12">
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title">
                            <i class="fa fa-phone fa-fw" aria-hidden="true"></i>
                            Contacts
                        </h3>
                    </div>
                    <div class="box-body">
                        <table class="table table-hover table-condensed">
                            <thead>
                                <tr>
                                    <th>Contact</th>
                                    <th>Number or Email</th>
                                    <th>Contact Description</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for contact in contacts %}
                                    <tr>
                                        <td>{{contact.name}}</td>
                                        <td>{{contact.number}}</td>
                                        <td>{{contact.description}}</td>
                                    </tr>
                                {% endfor %}
                            </tbody>
                            <tfoot></tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>

        {% if test_list.description or unit_test_collection.tests_object.description %}
            <div id="box-description" class="row" style="display: none;">
                <div class="col-sm-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">
                                <span class="fa fa-stack fa-fw" aria-hidden="true">
                                    <i class="fa fa-file-text-o fa-stack-custom-main"></i>
                                    <i class="fa fa-info fa-stack-custom-sub info"></i>
                                </span>
                                Description
                            </h3>
                        </div>
                        <div class="box-body">
                            {% spaceless %}
                                <div class="col-sm-12 pre text-display">
                                    {% if days and unit_test_collection.tests_object.description %}
                                        {% for day, display in days %}
                                            {% if day == current_day %}
                                                    <h5><b>Cycle Description: </b></h5>
                                                    <div>{{unit_test_collection.tests_object.description|safe|linebreaks}}</div>
                                                </div>
                                                <div class="col-sm-12 pre text-display">
                                                    <h5><b>Test List Description - {{ display }}: </b></h5>
                                            {% endif %}
                                        {% endfor %}
                                    {% endif %}
                                    <div>{{test_list.description.strip|safe|linebreaks}}</div>
                                </div>
                            {% endspaceless %}
                        </div>
                    </div>
                </div>
            </div>
        {% endif %}

          {% if form.errors %}
          <div class="row">
            <div class="col-sm-12">
              <ul class="alert alert-error">
              {% for field in form %}
                  {% for error in field.errors %}
                      <li>
                        {% if field != '__all__' %}
                          <strong>{{ field.label }}:</strong>
                        {% endif %}
                        {{ error }}
                      </li>
                  {% endfor %}
              {% endfor %}
              </ul>
            </div>
          </div>
        {% endif %}
        <div class="row" style="">

            {% if perms.qa.can_review and perms.qa.can_review_own_tests or perms.qa.can_override_date %}
                <div class="col-sm-{{ top_divs_span }}">
                    <div id="box-admin" class="box">
                        <div class="box-header">
                            <h3 class="box-title">
                                <i class="fa fa-unlock-alt" aria-hidden="true"></i>
                                Admin Options
                            </h3>
                        </div>
                        <div class="box-body">
                            <div class="row">
                                <div class="col-sm-12 form-horizontal">
                                    <div class="row {% if form.work_started.errors %} has-error{% endif %}">
                                        <label for="id_work_started" class="col-md-5">
                                            {{form.work_started.label}}:
                                        </label>
                                        <div class="col-md-7">
                                            {{form.work_started}}
                                            <i id="clear-work_started" class="fa fa-refresh fa-in-input datetime-clear"></i>
                                        </div>
                                        {% for e in form.work_started.errors %}
                                            <div class="col-sm-12 help-block text-center">{{ e }}</div>
                                        {% endfor %}
                                    </div>

                                    {% if perms.qa.can_override_date %}
                                        <div class="row">
                                            <label for="id_work_duration" class="col-md-5">
                                                Work duration:
                                            </label>
                                            <div class="col-md-7">
                                                <input id="id_work_duration" name="work_duration" class="form-control">
                                                <i class="fa fa-clock-o fa-in-input"></i>
                                            </div>
                                        </div>

                                        <div class="row{% if form.work_completed.errors %} has-error{% endif %}">
                                            <label for="id_work_completed" class="col-md-5">
                                                {{form.work_completed.label}}:
                                            </label>
                                            <div class="col-md-7">
                                                {{form.work_completed}}
                                                <i id="clear-work_completed" class="fa fa-times fa-in-input datetime-clear"></i>
                                            </div>
                                            {% for e in form.work_completed.errors %}
                                                <div class="col-sm-12 help-block text-center">{{ e }}</div>
                                            {% endfor %}
                                        </div>

                                        <div class="row{% if form.include_for_scheduling.errors %} has-error{% endif %}">
                                            <label for="id_include_for_scheduling" class="col-md-5">
                                                {{ form.include_for_scheduling.label}}:
                                            </label>
                                            <div class="col-md-1">
                                                {{ form.include_for_scheduling }}
                                            </div>
                                            <div class="col-md-6 help-block">
                                              {% trans "Uncheck if you don't want to advance the due date for this test list instance" %}
                                            </div>
                                            {% for e in form.include_for_scheduling.errors %}
                                                <div class="col-sm-12 help-block text-center">{{ e }}</div>
                                            {% endfor %}
                                        </div>
                                    {% endif %}
                                    {% if perms.qa.can_review and perms.qa.can_review_own_tests %}
                                        <div class="row" id="status">
                                            <label for="id_status" class="col-md-5">
                                                Set Status:
                                            </label>
                                            <div class="col-md-7">
                                                {{ form.status }}
                                            </div>
                                        </div>
                                    {% endif %}
                                </div>

                            </div>
                        </div>
                    </div>
                </div>
            {% else %}
                <div class="display-none">{{ form.include_for_scheduling }}</div>
                <div class="display-none">{{ form.work_started }}</div>
            {% endif %}

            <div class="col-sm-{{ top_divs_span }}">
                <div id="box-attachments">
                    <div class="box">
                        <div class="box-header">
                            <h5 class="box-title">
                                <i class="fa fa-paperclip" aria-hidden="true"></i>
                                {{ test_list.name }} Test List Attachments
                            </h5>
                        </div>
                        <div class="box-body">
                            <div class="row">
                                <div class="col-sm-12 border-default">
                                    <ul>
                                        {% for attach in attachments %}
                                            <li>{{ attach|attachment_link }}</li>
                                        {% endfor %}
                                    </ul>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            {% if form.instance.pk %}
                {% if perms.service_log.add_serviceevent or service_events_ib|length > 0 %}
                    <div class="col-sm-{{ top_divs_span }}">
                        <div id="box-serviceevents">
                            <div class="box">
                                <div class="box-header">
                                    <h5 class="box-title">
                                        <i class="fa fa-wrench" aria-hidden="true"></i>
                                        Service Events
                                    </h5>
                                </div>
                                <div class="box-body">
                                    <div class="row">
                                        <div class="col-sm-12">
                                            <div class="row">
                                                <label class="col-md-8">
                                                    {% if perms.service_log.add_serviceevent and unit_test_collection.unit.is_serviceable %}
                                                        <div class="btn-group">
                                                            <a class="btn btn-default btn-xs btn-flat hover-parent"
                                                               title="Create new service event initiated by this list"
                                                               href="{% url 'sl_new' %}?ib={{ form.instance.pk }}&next={{request.path|cut:"data/"}}"
                                                            >
                                                                <i class="fa fa-stack fa-fw">
                                                                    <i class="fa fa-wrench fa-stack-custom-main"></i>
                                                                    <i class="fa fa-plus fa-stack-custom-sub upper-0 hover-sub-success"></i>
                                                                </i>
                                                                {% if service_events_ib|length == 0 %}Initiate Service Event{% endif %}
                                                            </a>
                                                            <a class="btn btn-flat btn-xs btn-default new-tab-link"
                                                               href="{% url 'sl_new' %}?ib={{ form.instance.pk }}"
                                                               target="_blank"
                                                               title="New tab: Create new service event initiated by this list"
                                                            >
                                                                <i class="fa fa-chevron-right" aria-hidden="true"></i>
                                                            </a>
                                                        </div>
                                                        {% if service_events_ib|length > 0 %}Service events initiated:{% endif %}
                                                    {% endif %}
                                                </label>
                                                <div class="col-md-4">
                                                    {% for se in service_events_ib %}
                                                        {% if perms.service_log.view_serviceevent %}
                                                            <div class="btn-group">
                                                                <a href="{% url 'sl_details' pk=se.id %}"
                                                                   class="btn btn-xs btn-flat service-event-btn"
                                                                   data-bgcolour="{{ se.service_status.colour }}"
                                                                   title="View service event"
                                                                >{{ se.id }}</a>
                                                                <a class="btn btn-flat btn-xs btn-default new-tab-link service-event-btn"
                                                                   href="{% url 'sl_details' pk=se.id %}"
                                                                   target="_blank"
                                                                   title="New tab: view service event"
                                                                   data-bgcolour="{{ se.service_status.colour }}"
                                                                >
                                                                    <i class="fa fa-chevron-right" aria-hidden="true"></i>
                                                                </a>
                                                            </div>
                                                        {% else %}
                                                            <div>{{ se.id }}</div>
                                                        {% endif %}
                                                    {% endfor %}
                                                </div>
                                            </div>

                                            {% if service_events_rtsqa|length > 0 %}
                                                <div class="row margin-top-10">
                                                    <label class="col-md-8">
                                                        RTS QC for Service Events:
                                                    </label>
                                                    <div class="col-md-4">
                                                        {% for se in service_events_rtsqa %}
                                                            {% if perms.service_log.view_serviceevent %}
                                                                <div class="btn-group">
                                                                    <a href="{% url 'sl_details' pk=se.id %}"
                                                                       class="btn btn-xs btn-flat service-event-btn"
                                                                       data-bgcolour="{{ se.service_status.colour }}"
                                                                       title="View service event"
                                                                    >{{ se.id }}</a>
                                                                    <a class="btn btn-flat btn-xs btn-default new-tab-link service-event-btn"
                                                                       href="{% url 'sl_details' pk=se.id %}"
                                                                       target="_blank"
                                                                       title="New tab: view service event"
                                                                       data-bgcolour="{{ se.service_status.colour }}"
                                                                    >
                                                                        <i class="fa fa-chevron-right" aria-hidden="true"></i>
                                                                    </a>
                                                                </div>
                                                            {% else %}
                                                                <div>{{ se.id }}</div>
                                                            {% endif %}
                                                        {% endfor %}
                                                    </div>
                                                </div>
                                            {% endif %}
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                {% endif %}
            {% elif rtsqa_id %}
                <div class="col-sm-{{ top_divs_span }}">
                    <div id="box-serviceevents">
                        <div class="box">
                            <div class="box-header">
                                <h5 class="box-title">
                                    <i class="fa fa-wrench" aria-hidden="true"></i>
                                    Service Events
                                </h5>
                            </div>
                            <div class="box-body">
                                <div class="row">
                                    <div class="col-sm-12">
                                        <input name="rtsqa_id" type="hidden" value={{ rtsqa_id }}>
                                        Performing return to service qa for service event {% service_event_btn rtsqa_for_se %}
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            {% endif %}

        </div>


        <div id="box-perform" class="row">
            <div class="col-sm-12">
                <div class="box box-pho-borders">

                    <div class="box-header">
                        <div class="row">
                            <div class="col-sm-6">
                                {% if test_list_instance %}
                                    <i class="fa fa-pencil-square-o box-title" aria-hidden="true"></i>
                                    <h3 class="box-title">Edit {{test_list_instance.unit_test_collection.unit.name}} : {{test_list_instance.test_list.name}}</h3>
                                {% else %}
                                    <i class="fa fa-pencil-square-o box-title" aria-hidden="true"></i>
                                    <h3 class="box-title">Perform {{unit_test_collection.unit.name}} : {{test_list.name}}</h3>
                                {% endif %}
                                {% if days %}
                                    <div><em>Day {{ current_day }} from cycle : {{ unit_test_collection.name }}</em></div>
                                    {% if last_instance %}
                                        <div><em>Last done: {% if last_day %}Day {{last_day}} ({{last_instance.test_list.name}}){% else %}New list{%endif%}</em></div>
                                    {% endif %}
                                {% elif cycle_name %}
                                    <div><em>From cycle : {{ cycle_name }}</em></div>
                                {% endif %}

                            </div>

                            <div class="col-sm-6">
                                <span class="label label-info qa-calc-status pull-right">
                                  <i class="fa fa-check-circle fa-fw fa-lg" title="Calculations complete"></i>
                                  <span>Calculations Complete</span>
                                </span>
                                <span class="label label-warning qa-autosave-status pull-right">
                                    <i class="fa fa-save fa-fw fa-lg"></i>
                                  </i>
                                  <span>Not Saved</span>
                                </span>
                                {% if test_list.warning_message %}
                                    <h3 class="do-not-treat box-title pull-right">
                                        <strong>{{test_list.warning_message}}</strong>
                                    </h3>
                                {% endif %}
                            </div>
                        </div>
                    </div>

                    <div class="box-body">

                        <div class="row">
                            <div class="col-sm-12">

                                <!--input type="hidden" name="autosave-id" id="autosave-id" value=""/-->
                                {{ form.autosave_id }}
                                <input type="hidden" id="unit-test-collection-id" value="{{ unit_test_collection.pk }}"/>
                                <input type="hidden" id="test-list-id" value="{{test_list.pk}}"/>
                                <input type="hidden" id="test-list-name" value="{{test_list.name}}"/>
                                <input type="hidden" id="unit-id" value="{{unit_test_collection.unit.pk}}"/>
                                <input type="hidden" id="unit-number" value="{{unit_test_collection.unit.number}}"/>
                                <input type="hidden" id="cycle-day-number" value="{{current_day}}"/>

                                <input type="hidden" id="pass-fail-only" value="{% if perms.qa.can_view_ref_tol %}no{% else %}yes{% endif %}"/>
                                <input type="hidden" id="require-comment-on-skip" value="{% if perms.qa.can_skip_without_comment %}no{% else %}yes{% endif %}"/>

                                {% if formset.non_form_errors %}
                                    <div class="alert-message error">
                                        {% for error in formset.non_form_errors %}
                                            <span class="alert-error help-block-inline">{{ error }}</span>
                                        {% endfor %}
                                    </div>
                                {% endif %}

                                {{formset.management_form}}

                                <table id="perform-qa-table" class="qa-table table table-bordered table-responsive table-condensed">
                                    <thead>
                                        <tr>
                                            <th class="qa-category">Category</th>
                                            <th class="qa-showproc qa-name">Name</th>
                                            <th class="qa-value" width=100>Value</th>
                                            <th class="qa-skip">Skip</th>
                                            <th class="qa-status">Status</th>
                                            <th class="qa-showcmt">Comment</th>
                                            {% if perms.qa.can_view_ref_tol or perms.qa.can_view_history %}
                                                {% if perms.qa.can_view_ref_tol %}
                                                    <th class="qa-reference">Reference</th>
                                                {% endif %}
                                                {% if perms.qa.can_view_history %}
                                                    <th class="qa-history">History<br/>
                                                        {% for tli_url, d in history_dates %}
                                                          <a href="{{ tli_url}}" title="{% blocktrans %}Click to view this test list instance performed at {{ d }}{% endblocktrans %}">
                                                            <span class="label history-label">{{d|date:"dMy"}}</span>
                                                          </a>
                                                        {% endfor %}
                                                    <div></div></th>
                                                {% endif %}
{#                                            {% else %}#}
{#                                                <th>&nbsp;<div></div></th>#}
                                            {% endif %}
                                        </tr>
                                    </thead>
                                    {% for test_form in formset %}
                                        {% with borders.starts|lookup:forloop.counter0 as delim %}
                                            {% if delim and delim.class == "sublist" %}
                                              <tr class="{{delim.class }}">
                                                <td colspan="2">
                                                  {% if delim.description %}
                                                    <a class="show-sublist-details" href="#">
                                                      {{ delim.name }}
                                                    </a>
                                                  {% else %}
                                                      {{ delim.name }}
                                                  {% endif %}
                                                </td>
                                                <td colspan="{% qa_table_colspan perms offset=2 %}">&nbsp;</td>
                                              </tr>

                                              <tr class="qa-procedure no-hover">
                                                  <td colspan="{% qa_table_colspan perms %}">
                                                      <div>
                                                        <div class="procedure-container procedure-bar">
                                                            <div class="qa-procedure-text">
                                                                {% if delim.description %}
                                                                    <div class="pre">{{ delim.description | safe }}</div>
                                                                {% endif %}
                                                            </div>
                                                        </div>
                                                      </div>
                                                  </td>
                                              </tr>
                                            {% endif %}

                                            {% if delim.class == "sublist" or test_form.get_test_info.show_category %}
                                              {% qa_value_form test_form test_list perms user test_info=test_form.get_test_info unit_test_collection=unit_test_collection show_category=1 %}
                                            {% else %}
                                              {% qa_value_form test_form test_list perms user test_info=test_form.get_test_info unit_test_collection=unit_test_collection show_category=0 %}
                                            {% endif %}

                                        {% endwith %}


                                        {% if not forloop.last and borders.ends|lookup:forloop.counter0 %}
                                          {% with borders.starts|lookup:forloop.counter as delim %}
                                            {% if not delim or delim.class != "sublist" %}
                                            <tr class="end-sublist">
                                                <td colspan="{% qa_table_colspan perms %}"></td>
                                            </tr>
                                            {% endif %}
                                          {% endwith %}

                                        {% endif %}

                                    {% endfor %}
                                </table>

                                <div class="row">
                                    <div class="col-sm-7">
                                        {% if perms.attachments.add_attachment %}
                                            <table class="table table-responsive table-condensed">
                                                <tbody>
                                                    <tr>
                                                        <td class="width-"><strong>Attachments</strong></td>
                                                        <td>
                                                            <label class="qa-input btn btn-default btn-sm btn-flat" title="Click to add attachments. (Hold Ctrl or Cmd in the dialog to include multiple attachments)">
                                                                Browse {{ form.tli_attachments }}
                                                            </label>
                                                        </td>

                                                        <td id="tli-attachment-names" colspan="{% qa_table_colspan perms offset=2 %}">

                                                        {% if test_list_instance and test_list_instance.attachment_set.all|length > 0 %}
                                                            {% for attach in test_list_instance.attachment_set.all %}
                                                                <i class="fa fa-paperclip fa-fw" aria-hidden="true"></i>{{ attach | attachment_link }}
                                                            {% endfor %}
                                                        {% endif %}
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        {% endif %}
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-sm-12">

                                        <button id="submit-qa" type="submit" class="btn btn-primary btn-flat margin-r-5 pull-right">Submit QC Results</button>

{#                                        <a id="toggle-gen-comment" class="btn btn-default btn-flat pull-right margin-r-5" href="#!" title="Click here to add a general comment about this set of tests">Add Comment</a>#}

                                        <div id="in-progress-container" class="pull-right margin-r-5">
                                            {% if perms.qa.can_save_in_progress %}
                                            <label title="{{form.in_progress.help_text}}" for="id_in_progress" class="add-on" style="display: none;">
                                                Mark this list as still in progress:
                                            </label>
                                            {{form.in_progress}}
                                            {% endif %}
                                        </div>

                                        <div id="init-se-container" class="pull-right margin-r-5">
                                            {% if perms.service_log.add_serviceevent and unit_test_collection.unit.is_serviceable %}
                                              <label title="{{form.initiate_service.help_text}}" for="id_initiate_service" class="add-on" style="display: none;">
                                                  Initiate service event:
                                              </label>
                                              {{ form.initiate_service }}
                                            {% endif %}
                                        </div>

                                    </div>
                                </div>

                                <div id="qa-images">
                                    {% for test_form in formset %}
                                        {% with test=test_form.get_test_info.test ti=test_form.instance %}
                                            {% if test.display_image %}
                                                <div class="row">
                                                    <div class="col-sm-12">
                                                        <strong><p>Images for {{ test }} Test: </p></strong>
                                                    </div>
                                                </div>
                                                <div class="row">
                                                    <div id="{{ test.slug }}"></div>
                                                </div>
                                            {% endif %}
                                        {% endwith %}
                                    {% endfor %}
                                </div>
                            </div>
                        </div>
                    </div>

                    {% if test_list.warning_message %}
                        <div class="box-footer">
                            <div class="row">
                                <div class="col-sm-12">
                                    <h3 class="do-not-treat box-title pull-right">
                                        <strong>{{test_list.warning_message}}</strong>
                                    </h3>
                                </div>
                            </div>
                        </div>
                    {% endif %}
                </div>
            </div>
        </div>

    {% if test_list_instance %}

    </form>
        <div id="box-comments" class="row">
            <div class="col-sm-12">
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title">
                            <i class="fa fa-commenting-o fa-fw"></i>
                            Comments
                        </h3>
                    </div>
                    <div class="box-body">
                        <div class="row">
                            <div class="col-md-12">
                                {% render_comment_list for test_list_instance %}
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12 padding-top-20">
                                {% get_comment_form for test_list_instance as form %}

                                    <form id="comment-form" method="post">
                                        {% csrf_token %}
                                        <input id="edit-tli" name="edit-tli" type="hidden" value="edit-tli">
                                        <input id="id_name" maxlength="50" name="name" type="hidden" required="" value="{{ user.username }}">
                                        {{ form.object_pk }}
                                        {{ form.content_type }}
                                        {{ form.security_hash }}
                                        {{ form.timestamp }}
                                        <textarea cols="40" id="id_comment" maxlength="3000" name="comment" rows="3" required="" placeholder="Add comment" class="margin-bottom-20 form-control autosize"></textarea>

                                    </form>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <button id="post-comment" class="btn btn-flat btn-info btn-sm pull-right" disabled="disabled">Post Comment</button>
                                        </div>
                                    </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    {% else %}
        <div id="box-comments" class="row">
          <a id="comments-anchor"></a>
            <div class="col-sm-12">
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title">
                            <i class="fa fa-commenting-o fa-fw"></i>
                            Comments
                        </h3>
                    </div>
                    <div class="box-body">
                        <div id="qa-tli-comment">
                            {{ form.comment }}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    {% endif %}
    </div>



{% endblock %}

{% block main_sidebar %}
    <aside class="main-sidebar">

        <section class="sidebar">

            <ul class="sidebar-menu">

                <li class="header">Test List Menu</li>

                {% if test_list.description or unit_test_collection.tests_object.description %}
                    <li class="primary toggle-element" data-toggle="description"><a id="toggle-description" href="#!">
                        <i class="fa fa-stack fa-fw" aria-hidden="true">
                            <i class="fa fa-file-text-o fa-stack-custom-main"></i>
                            <i class="fa fa-info fa-stack-custom-sub info"></i>
                        </i>
                        <span>Description</span>
                    </a></li>
                {% endif %}

                {% if perms.qa.can_review and perms.qa.can_review_own_tests or perms.qa.can_override_date %}
                    <li title="Toggle admin options visibility" class="primary toggle-element active" data-toggle="admin"><a id="toggle-options" href="#!">
                        <i class="fa fa-unlock-alt fa-fw" aria-hidden="true"></i>
                        <span>Admin Options</span>
                    </a></li>
                {% endif %}

                {% if attachments|length > 0 %}
                    <li class="primary toggle-element active" data-toggle="attachments"><a id="toggle-options" href="#!">
                        <i class="fa fa-paperclip fa-fw" aria-hidden="true"></i>
                        <span>Attachemnts</span>
                    </a></li>
                {% endif %}

                {% if form.instance.pk or rtsqa_id %}
                    {% if perms.service_log.add_serviceevent or service_events_ib|length > 0 %}
                        <li class="primary toggle-element active" data-toggle="serviceevents"><a id="toggle-options" href="#!">
                            <i class="fa fa-wrench fa-fw" aria-hidden="true"></i>
                            <span>Service Events</span>
                        </a></li>
                    {% endif %}
                {% endif %}

                <li title="Toggle comments visibility" class="primary toggle-element active" data-toggle="comments"><a id="toggle-options" href="#!">
                    <i class="fa fa-commenting-o fa-fw" aria-hidden="true"></i>
                    <span>Comments</span>
                </a></li>

                {# Category selection #}
                {% if perms.qa.can_perform_subset and categories|length > 1 %}
                    <li class="treeview">
                        <a id="menu-categories" href="#!">
                            <i class="fa fa-tags fa-fw" aria-hidden="true"></i>
                            <span>Categories</span>
                            <i class="fa fa-angle-left pull-right"></i>
                        </a>
                        <ul id="category-list" class="treeview-menu" style="display: none;">
                            <li><a {% comment %}id="category-showall"{% endcomment %} class="has-icheck row" href="#!">
{#                                <i class="fa fa-circle-o success"></i>#}
                                <input id="category-showall" class="iCheck" type="checkbox" checked="checked">
                                <label for="category-showall">Show All</label>
                            </a></li>

                            {% for category in categories %}
                                <li><a class="has-icheck row" href="#!">
                                    <input id="category-{{ category.pk }}" class="iCheck check-category" type="checkbox" checked="checked">
                                    <label for="category-{{ category.pk }}">{{ category.name }}</label>
                                </a></li>
                            {% endfor %}

                        </ul>
                    </li>
                {% endif %}

                {# days selection #}
                {% if days %}
                    {% with unit_test_collection.tests_object as tlc %}
                        <li class="treeview">
                            <a id="menu-days" href="#!">
                                <i class="fa fa-calendar fa-fw" aria-hidden="true"></i>
                                <span>{{ tlc.drop_down_label }}</span>
                                <i class="fa fa-angle-left pull-right"></i>
                            </a>
                            <ul id="days-list" class="treeview-menu" style="display: none;">

                                <li><a class="has-icheck row" href="#">
                                    <input id="day-next" class="iCheck radio-days" type="radio" name="iCheck">
                                    <label for="day-next">Next scheduled</label>
                                </a></li>
                                {% for day, display in days %}
                                    <li><a class="has-icheck row" href="#">
                                        <input id="day-{{ day }}" class="iCheck radio-days" type="radio" name="iCheck" {% if day == current_day %}checked="checked"{% endif %}>
                                        <label for="day-{{ day }}">{{ display }}</label>
                                    </a></li>
                                {% endfor %}
                            </ul>
                        </li>
                    {% endwith %}
                {% endif %}

                <li class="divider"></li>
                <li title="Click to toggle contacts visibility" class="primary toggle-element" data-toggle="contacts">
                  <a id="toggle-contacts" href="#!">
                    <i class="fa fa-phone fa-fw" aria-hidden="true"></i>
                    <span>Contacts</span>
                  </a>
                </li>

                {% if in_progress %}
                  <li class="divider"></li>
                  <li class="treeview">
                    <a id="menu-days" href="#!">
                      <i style="color: #f39c12;" class="fa fa-play fa-fw" aria-hidden="true"></i>
                      <span>In Progress</span>
                      <i class="fa fa-angle-left pull-right"></i>
                    </a>
                    <ul id="in-progress-list" class="treeview-menu" style="display: none;">
                      {% for ip in in_progress %}
                        <li>
                          <a title="Resume session saved by {{ ip.created_by }}" class="row" href="{% url 'continue_tli' pk=ip.pk %}?{{ request.GET.urlencode }}">
                            {{ ip.created }}
                          </a>
                        </li>
                      {% endfor %}
                    </ul>
                  </li>
                {% endif %}

                {% if autosaves %}
                  <li class="divider"></li>
                  <li class="treeview">
                    <a id="menu-days" href="#!">
                      <i style="color: #f39c12;" class="fa fa-save fa-fw" aria-hidden="true"></i>
                      <span>Auto Saved Sessions</span>
                      <i class="fa fa-angle-left pull-right"></i>
                    </a>
                    <ul id="autosave-list" class="treeview-menu" style="display: none;">
                      {% for auto in autosaves %}
                        <li>
                          <a title="Resume session auto-saved for {{ auto.modified_by }} on {{ auto.modified }}"
                             class="row"
                             href="{% if auto.test_list_instance_id %}{% url "continue_tli" pk=auto.test_list_instance_id %}{% endif %}?autosave_id={{ auto.id }}&day={{ auto.day | add:"1" }}&next={{ request.GET.next }}"
                          >
                            {{ auto.modified }}
                          </a>
                        </li>
                      {% endfor %}
                    </ul>
                  </li>
                {% endif %}

                <li class="divider"></li>
                <li title="{% trans "Click to log a new fault" %}" class="primary toggle-element">
                  <a class="fault-modal-toggle" href="#" data-target="#fault-modal" data-toggle="modal">
                    <i class="fa fa-exclamation-triangle fa-fw" aria-hidden="true"></i>
                    <span>{% trans "Log Fault" %}</span>
                  </a>
                </li>

            </ul>

        </section>

    </aside>
{% endblock main_sidebar %}

{% block loading_modal %}
    <div class="loading-modal ">
        <div class="loading-modal-center">
            <div>
                <span class="loading-logo">QAT</span>
                <i class="fa fa-fw fa-plus fa-spin fa-2x info"></i>
            </div>
            <div>
                <b>
                {% if test_list_instance %}
                    Loading {{test_list_instance.unit_test_collection.unit.name}} : {{test_list_instance.test_list.name}}
                {% else %}
                    Loading {{unit_test_collection.unit.name}} : {{test_list.name}}
                {% endif %}
                </b>
            </div>

        </div>
    </div>
{% endblock loading_modal %}

{% block extra_body %}
<div id="fault-modal" class="fault-modal modal fade" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">{% trans "Log a new fault" %}</h4>
      </div>
      <div class="modal-body">
        <form id="fault-form"
          data-create-url="{% url "fault_create_ajax" %}"
          action=""
          novalidate
          autocomplete="off"
        >
          <div class="form-group">
            <div id="modal-fault-message" class="col-sm-offset-4 col-sm-8">
            </div>
          </div>

          {% csrf_token %}
          <div class="row">
            <div class="col-md-12 form-horizontal">
              <fieldset>
                {% include "_form_horizontal.html" with form=fault_form %}
              </fieldset>
            </div>
          </div>
          <div class="row">
            <div class="col-md-12 form-horizontal">
              <fieldset>
                {% for review_form in review_forms %}
                  <div class="form-group {% if review_form.errors %}has-error{% endif %}">
                    <label class="col-sm-3 control-label" for="{{ review_form.group.id_for_label }}">
                      {{ review_form.group.label }} {% if review_form.reviewed_by.field.required %}*{% endif %}
                    </label>
                    <div class="col-sm-3">
                      {{ review_form.group|add_class:"form-control input-sm" }}
                    </div>
                    <label class="col-sm-3 control-label" for="{{ review_form.reviewed_by.id_for_label }}">
                      {{ review_form.reviewed_by.label }}
                    </label>
                    <div class="col-sm-3">
                      {{ review_form.reviewed_by|add_class:"form-control input-sm reviewed-by-select" }}
                      {% if review_form.errors.reviewed_by %}
                        <div class="help-block error-message">
                          {% for err in review_form.errors.reviewed_by %}
                            {{ err }}
                          {% endfor %}
                        </div>
                      {% endif %}
                    </div>
                  </div>
                {% endfor %}
              </fieldset>
            </div>
          </div>
        </form>
      </div>
      <div class="modal-footer">

        <button type="button" class="btn btn-default btn-flat pull-left" data-dismiss="modal">
          <i class="fa fa-ban"></i>
          {% trans "Cancel" %}
        </button>
        <button id="save_fault" type="button" class="btn btn-flat btn-primary">
          <i class="fa fa-save"></i>
          {% trans "Log Fault" %}
        </button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div>
{% endblock %}

{% block end_body_extra_script %}

{% endblock %}



